package com.example.demo.mapper;

import com.example.demo.pojo.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    List<AddressBook> list(AddressBook addressBook);


    @Insert("insert into address_book (user_id, consignee, sex, phone, province_name, city_name, district_name, detail, label,is_default) " +
            "values " +
            "(#{userId},#{consignee},#{sex},#{phone},#{provinceName},#{cityName},#{districtName},#{detail},#{label},#{isDefault});")
    void insert(AddressBook addressBook);

    @Select("select * from address_book where is_default=1")
    AddressBook getDefault();

    @Select("select * from address_book where id=#{id}")
    AddressBook getById(Long id);

    void update(AddressBook addressBook);

    @Delete("delete from address_book where id=#{id}")
    void deleteById(Long id);

    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
}
